package c.c.b.b.f;

import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import c.c.b.b.e.f;
import c.c.b.b.i.c;
import c.c.b.b.i.d;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.atomic.AtomicInteger;

/* compiled from: RequestQueue */
public class o {
    public final AtomicInteger a = new AtomicInteger();
    public final Set<c<?>> b = new HashSet();
    public final PriorityBlockingQueue<c<?>> c = new PriorityBlockingQueue();
    public final PriorityBlockingQueue<c<?>> d = new PriorityBlockingQueue();
    public final c.c.b.b.i.b e;
    public final c f;
    public final d g;
    public final l[] h;
    public h i;
    public final List<b> j = new ArrayList();
    public final List<a> k = new ArrayList();

    /* compiled from: RequestQueue */
    public interface a {
        void a(c<?> cVar, int i);
    }

    @Deprecated
    /* compiled from: RequestQueue */
    public interface b<T> {
        void a(c<T> cVar);
    }

    public o(c.c.b.b.i.b bVar, c cVar) {
        k kVar = new k(new Handler(Looper.getMainLooper()));
        this.e = bVar;
        this.f = cVar;
        this.h = new l[4];
        this.g = kVar;
    }

    public <T> c<T> a(c<T> cVar) {
        if (!(cVar == null || TextUtils.isEmpty(cVar.getUrl()))) {
            CharSequence url = cVar.getUrl();
            c.c.b.b.e.a aVar = c.c.b.b.c.d;
            if (aVar != null) {
                c.c.b.b.b.a aVar2 = (c.c.b.b.b.a) aVar;
                if (!TextUtils.isEmpty(url)) {
                    if (Looper.myLooper() == Looper.getMainLooper()) {
                        try {
                            url = f.a().b(url);
                        } catch (Throwable unused) {
                        }
                    } else {
                        if (aVar2.a) {
                            aVar2.i();
                        } else {
                            aVar2.f();
                        }
                        url = f.a().b(url);
                    }
                }
                if (!TextUtils.isEmpty(url)) {
                    cVar.setUrl(url);
                }
            }
        }
        cVar.setStartTime();
        cVar.setRequestQueue(this);
        synchronized (this.b) {
            this.b.add(cVar);
        }
        cVar.setSequence(this.a.incrementAndGet());
        cVar.addMarker("add-to-queue");
        b(cVar, 0);
        if (cVar.shouldCache()) {
            this.c.add(cVar);
            return cVar;
        }
        this.d.add(cVar);
        return cVar;
    }

    public void b(c<?> cVar, int i) {
        synchronized (this.k) {
            for (a a : this.k) {
                a.a(cVar, i);
            }
        }
    }
}
